package cn.matrix42.potoo.format.markdown.element.text.code;

import java.util.ArrayList;
import java.util.List;

import cn.matrix42.potoo.format.markdown.element.MarkdownElement;
import cn.matrix42.potoo.lang.Preconditions;

public class MathBlock extends MarkdownElement {

    private List<String> formulaList = new ArrayList<>();

    public MathBlock() {
    }

    public MathBlock(List<String> formulaList) {
        Preconditions.checkNotNull(formulaList);
        this.formulaList = formulaList;
    }

    public void addFormula(String formula) {
        Preconditions.checkNotNull(formula);
        formulaList.add(formula);
    }

    public void addFormulas(List<String> formulas) {
        Preconditions.checkNotNull(formulaList);
        formulaList.addAll(formulas);
    }

    public List<String> getFormulaList() {
        return formulaList;
    }

    @Override
    public List<String> toMarkdownStringList() {
        List<String> list = new ArrayList<>();
        list.add("$$");
        list.addAll(formulaList);
        list.add("$$");
        list.add(context.getConfig().getEof());
        return list;
    }

    public static MathBlock of() {
        return new MathBlock();
    }

    public static MathBlock of(List<String> formulaList) {
        return new MathBlock(formulaList);
    }

}
